package controller;

import javax.swing.JOptionPane;

import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import domain.User;
import facade.facade;

@Controller
public class HelloWorldController {

	@RequestMapping("/hello")
	public ModelAndView helloWorld() {

		String message = "Hello World, Spring 3.0!";
		return new ModelAndView("hello", "message", message);
	}

	@RequestMapping(value = "/login", method = RequestMethod.POST)
	public ModelAndView newUser(

	@ModelAttribute("user") User user, BindingResult result) {
		facade fa = new facade();
		//System.out.println("Usuario inserido: " + user.getLogin());
		//User userBd = new User();
		//userBd = fa.procurarUsuario(user.getLogin());
		//System.out.println("Usuario do banco: " + userBd.getLogin());
		if (fa.logar(user.getLogin(), user.getPass())) {

			JOptionPane.showMessageDialog(null, "Usuario aceito");

		} else {
			JOptionPane.showMessageDialog(null, "Senha nao confere");
		}
		;

		return new ModelAndView();
	}

	@RequestMapping("/appareal")
	public ModelAndView appareal() {

		return new ModelAndView();
	}

	@RequestMapping("/gear")
	public ModelAndView gear() {

		return new ModelAndView();
	}

	@RequestMapping("/camping")
	public ModelAndView camping() {

		return new ModelAndView();
	}

	@RequestMapping("/books")
	public ModelAndView books() {

		return new ModelAndView();
	}

	@RequestMapping("/audiov")
	public ModelAndView audiov() {

		return new ModelAndView();
	}

	@RequestMapping("/food")
	public ModelAndView food() {

		return new ModelAndView();
	}

}